window.onload = function () {
    display_name();
    people_number();
    jj();
    not_set();
    not_display();
    resolve()


}

function jumpheader(){
    location.href="http://localhost:3000/welcome/header"
}
function jumpselectpeople(){
    location.href='../welcome/select_people.haml'

}
function jumporder(){
    location.href='../../welcome/order.haml'
}
function jump_restaurant(){
    localStorage.removeItem("package_name");
    location.href='../welcome/choose_restaurant.haml'
}
var result;
function jump_check_order(){
    location.href="../welcome/check_order.haml"

}

function people_number(){
    var url = "/welcome/get_order";
    var date = form_object();
    var sum=[];
    $.ajaxSettings.async = false;
    var success = function (result) {
        for(var i=0;i<result.length;i++) {
            if(sum.indexOf(result[i].people)==-1)
                sum.push(result[i].people)
        }


            }

    var error = function () {
        alert("失败");
    };

    post_ajax(url, date,success,error);
    return sum;

}


function jj(){
    var nn=people_number();
    var mm=nn.length+"人已订";
    $("p#book").append(mm);
    $("p#sum_up").append(mm);
}
function not_order(){
    var url = "/welcome/not_order";
    var date = form_object();
    var add=[];
    $.ajaxSettings.async = false;
    var success = function (not) {
        var idea=people_number();
        for(var i=0;i<not.length;i++) {
            if (idea.indexOf(not[i]) == -1) {

                add.push(not[i])

            }
        }

    };
    var error = function () {
        alert("失败");
    };

    post_ajax(url, date,  success,error);
    return add;

}

function not_set(){
    var ace=not_order();
    var sorry=ace.length+"人未订";
    var good=","+ace.length+"人未订"+",";
    $("p#look").append(sorry);
    $("p#sum_up").append(good);
}
function not_display(){
    var people = not_order();
    var a;
    for(var i=0;i<people.length;i++){
        a="<li class='not_order_people'>"+people[i]+"</li>"
        $("ul#not_display").append(a);
    }

}
function resolve(){
    var url = "/welcome/resolve";
    var date = form_object();
    var a=0;
    $.ajaxSettings.async = false;
    var success = function (data) {
        console.log(data)
        for(var i=0;i<data.length;i++){
            var b=data[i].price;
            var s=b.substr(1,5);
            a+=Number(s);
            console.log(a)

        }



    };
    var error = function () {
        alert("失败");
    };
    post_ajax(url, date, success,error);
    var sum_price="总计"+a+"元";
    $("p#sum_up").append(sum_price);


}
function qq(){
    var ss=[{"price":"￥10.00"}];
    var a=parseInt('ss[0].price');
    //var iNum1 = parseInt("12345red");
    console.log(a)

}



